home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / prim / extents.el.z / extents.el
Encoding:
Text File  |  1998-05-21  |  3.9 KB  |  97 lines

  1. ;;; extents.el --- miscellaneous extent functions not written in C
  2.  
  3. ;;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Keywords: internal
  6.  
  7. ;; This file is part of XEmacs.
  8.  
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; XEmacs is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  21. ;; Free Software Foundation, 59 Temple Place - Suite 330,
  22. ;; Boston, MA 02111-1307, USA.
  23.  
  24. ;;; Synched up with: Not in FSF.
  25.  
  26. ; some help from stig@hackvan.com here.
  27.  
  28. ;; an alternative to map-extents.
  29. (defun mapcar-extents (function &optional predicate buffer-or-string from to
  30.                 flags property value)
  31.   "Applies FUNCTION to all extents which overlap a region in BUFFER-OR-STRING.
  32. The region is delimited by FROM and TO.  FUNCTION is called with
  33. one argument, the extent.  A list of the values returned by FUNCTION
  34. is returned.  An optional PREDICATE may be used to further limit the
  35. extents over which FUNCTION is mapped.  The optional arguments FLAGS,
  36. PROPERTY, and VALUE may also be used to control the extents passed to
  37. PREDICATE or FUNCTION.  See also `map-extents'."
  38.   (let (*result*)
  39.     (map-extents (if predicate
  40.                      #'(lambda (ex junk)
  41.                          (and (funcall predicate ex)
  42.                               (setq *result* (cons (funcall function ex)
  43.                                                    *result*)))
  44.                          nil)
  45.                    #'(lambda (ex junk)
  46.                          (setq *result* (cons (funcall function ex)
  47.                                               *result*))
  48.                          nil))
  49.                  buffer-or-string from to nil flags property value)
  50.     (nreverse *result*)))
  51.  
  52. (defun extent-list (&optional buffer-or-string from to flags)
  53.   "Return a list of the extents in BUFFER-OR-STRING.
  54. BUFFER-OR-STRING defaults to the current buffer if omitted.
  55. FROM and TO can be used to limit the range over which extents are
  56. returned; if omitted, all extents in the buffer or string are returned.
  57.  
  58. More specifically, if a range is specified using FROM and TO, only
  59. extents that overlap the range (i.e. begin or end inside of the range)
  60. are included in the list.  FROM and TO default to the beginning and
  61. end of BUFFER-OR-STRING, respectively.
  62.  
  63. FLAGS controls how end cases are treated.  For a discussion of this,
  64. and exactly what ``overlap'' means, see `map-extents'.
  65.  
  66. If you want to map a function over the extents in a buffer or string,
  67. consider using `map-extents' or `mapcar-extents' instead."
  68.   (mapcar-extents 'identity nil buffer-or-string from to flags))
  69.  
  70. (defun extent-string (extent)
  71.   "Return the string delimited by the bounds of EXTENT."
  72.   (let ((object (extent-object extent)))
  73.     (if (bufferp object)
  74.     (buffer-substring (extent-start-position extent)
  75.               (extent-end-position extent)
  76.               object)
  77.       (substring object
  78.          (extent-start-position extent)
  79.          (extent-end-position extent)))))
  80.  
  81. (defun extent-descendants (extent)
  82.   "Return a list of all descendants of EXTENT, including EXTENT.
  83. This recursively applies `extent-children' to any children of
  84. EXTENT, until no more children can be found."
  85.   (let ((children (extent-children extent)))
  86.     (if children
  87.     (apply 'nconc (mapcar 'extent-descendants children))
  88.       (list extent))))
  89.  
  90. (defun set-extent-keymap (extent keymap)
  91.   "Set EXTENT's `keymap' property to KEYMAP."
  92.   (set-extent-property extent 'keymap keymap))
  93.  
  94. (defun extent-keymap (extent)
  95.   "Return EXTENT's `keymap' property."
  96.   (extent-property extent 'keymap))
  97.